import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class timer extends JFrame implements ActionListener
{

	int x=100, dx=1;
	javax.swing.Timer animationTimer;
	
    public static void main(String[] args) {
        new timer();
    }

    /**
     * Constructor for objects of class BattleshipApp
     */
    public timer()
    {	
        setSize(600, 600);
		show();
		animationTimer = new javax.swing.Timer(20, this);
		actionPerformed(new ActionEvent(this,3,"Run"));
    }

    public void paint(Graphics gfx) {}


	public void actionPerformed(ActionEvent e){
		Graphics gfx = this.getGraphics();
        gfx.clearRect(0, 0, 800, 800);
		gfx.setColor(Color.black);
		gfx.drawOval(x, 300, 100, 100);
		x += dx;
		if(x > 500) dx = -dx;
		if(x < 100) {
			dx = -dx;
			animationTimer.stop();
		}
		else animationTimer.start();
	}
}
